﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

public class DBUtils{
    public static T Pack<T>(MySqlDataReader reader){
        Type type = typeof(T);
        T ret = (T) type.Assembly.CreateInstance(type.FullName);
        FieldInfo[] fields = type.GetFields();
        foreach (FieldInfo filed in fields){
            if (filed.FieldType.FullName == typeof(string).FullName){
                filed.SetValue(ret, reader.GetString(filed.Name));
            }
            else if (filed.FieldType.FullName == typeof(Int32).FullName){
                filed.SetValue(ret, reader.GetInt32(filed.Name));
            }
            else if (filed.FieldType.FullName == typeof(Int64).FullName){
                filed.SetValue(ret, reader.GetInt64(filed.Name));
            }
        }

        return ret;
    }
}
